﻿using System;
using System.Collections.Generic;

namespace DependencyAnalysis.DataModel
{
    public static class DependencyModelConverter
    {
        public static IDictionary<IDescriptor, ISet<DependencyDescriptor>> GetDependencyStructureIn<T>(IDependencyModel model) where T : IDescriptor
        {
            if (typeof(T) == typeof(MemberDescriptor))
            {
                return model.DependenciesPerMember;
            }
            if (typeof(T) == typeof(TypeDescriptor))
            {
                return model.DependenciesPerType;
            }
            if (typeof(T) == typeof(SubmoduleDescriptor))
            {
                return model.DependenciesPerSubmodule;
            }
            if (typeof(T) == typeof(ModuleDescriptor))
            {
                return model.DependenciesPerModule;
            }
            throw new ArgumentException();
        }

        public static IDictionary<IDescriptor, ISet<DependencyDescriptor>> GetDependencyStructureOut<T>(IDependencyModel model) where T : IDescriptor
        {
            if (typeof(T) == typeof(MemberDescriptor))
            {
                return model.DependenciesPerMemberOut;
            }
            if (typeof(T) == typeof(TypeDescriptor))
            {
                return model.DependenciesPerTypeOut;
            }
            if (typeof(T) == typeof(SubmoduleDescriptor))
            {
                return model.DependenciesPerSubmoduleOut;
            }
            if (typeof(T) == typeof(ModuleDescriptor))
            {
                return model.DependenciesPerModuleOut;
            }
            throw new ArgumentException();
        }
    }
}
